<!DOCTYPE html>
<html>
<head>
    <title>Hall Effect Diagram</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        canvas {
            border: 1px solid #ccc;
            background-color: white;
        }
    </style>
</head>
<body>
    <canvas id="physics-canvas" width="650" height="550"></canvas>
    <script>
        const canvas = document.getElementById('physics-canvas');
        const ctx = canvas.getContext('2d');

        // Style settings
        ctx.lineWidth = 1.5;
        ctx.font = 'bold 16px "Times New Roman"';
        ctx.strokeStyle = 'black';
        ctx.fillStyle = 'black';

        // Helper function to draw an arrow
        function drawArrow(fromX, fromY, toX, toY) {
            const headlen = 10;
            const dx = toX - fromX;
            const dy = toY - fromY;
            const angle = Math.atan2(dy, dx);
            ctx.moveTo(fromX, fromY);
            ctx.lineTo(toX, toY);
            ctx.lineTo(toX - headlen * Math.cos(angle - Math.PI / 6), toY - headlen * Math.sin(angle - Math.PI / 6));
            ctx.moveTo(toX, toY);
            ctx.lineTo(toX - headlen * Math.cos(angle + Math.PI / 6), toY - headlen * Math.sin(angle + Math.PI / 6));
        }
        
        // --- Draw the cuboid ---
        // Coordinates are chosen to visually match the provided image.
        const P = { x: 224, y: 218 };
        const Q = { x: 224, y: 321 };
        const F = { x: 128, y: 372 };
        const S = { x: 467, y: 165 };
        const R = { x: 513, y: 273 };
        const G = { x: 416, y: 323 };
        const H = { x: 420, y: 212 }; // Point for dashed lines

        // Draw solid lines (visible edges)
        ctx.beginPath();
        ctx.moveTo(P.x, P.y); ctx.lineTo(S.x, S.y);
        ctx.moveTo(S.x, S.y); ctx.lineTo(R.x, R.y);
        ctx.moveTo(R.x, R.y); ctx.lineTo(G.x, G.y);
        ctx.moveTo(G.x, G.y); ctx.lineTo(F.x, F.y);
        ctx.moveTo(F.x, F.y); ctx.lineTo(Q.x, Q.y);
        ctx.moveTo(Q.x, Q.y); ctx.lineTo(P.x, P.y);
        ctx.moveTo(Q.x, Q.y); ctx.lineTo(R.x, R.y);
        ctx.stroke();

        // Draw dashed lines (hidden edges)
        ctx.beginPath();
        ctx.setLineDash([4, 4]);
        ctx.moveTo(S.x, S.y); ctx.lineTo(H.x, H.y);
        ctx.moveTo(H.x, H.y); ctx.lineTo(G.x, G.y);
        
        // This third dashed line is less clear in the original, but implies the back corner
        // It connects H to the hidden vertex behind P/Q.
        const hidden_back_left_vertex_vec = {x: P.x - Q.x, y: P.y - Q.y};
        const hidden_back_left_vertex = {x: F.x + (S.x-G.x), y: F.y + (S.y-G.y)}; // Approximation
        const hidden_back_top_left_vertex = {x: P.x + (H.x - S.x), y: P.y + (H.y-S.y)};
        ctx.moveTo(H.x, H.y);
        ctx.lineTo(hidden_back_top_left_vertex.x, hidden_back_top_left_vertex.y); // Line towards back-left
        ctx.stroke();
        ctx.setLineDash([]); // Reset to solid lines

        // --- Draw labels for vertices ---
        ctx.fillText('P', P.x - 20, P.y);
        ctx.fillText('Q', Q.x + 10, Q.y);
        ctx.fillText('F', F.x - 20, F.y + 10);
        ctx.fillText('S', S.x + 10, S.y);
        ctx.fillText('R', R.x + 10, R.y - 5);
        ctx.fillText('G', G.x + 10, G.y + 15);
        ctx.fillText('H', H.x + 5, H.y - 5);
        ctx.fillText('E', 125, 298); // Label 'E' on the middle electron line

        // --- Draw arrows for incident electrons ---
        ctx.beginPath();
        drawArrow(50, 270, 150, 270);
        drawArrow(50, 290, 150, 290);
        drawArrow(50, 310, 150, 310);
        ctx.stroke();
        
        // Label for electrons
        ctx.textAlign = "left";
        ctx.fillText('direction of', 50, 350);
        ctx.fillText('incident electrons', 50, 370);
        
        // --- Draw arrows for magnetic field ---
        ctx.beginPath();
        drawArrow(350, 80, 350, 160);
        drawArrow(400, 80, 400, 160);
        drawArrow(450, 80, 450, 160);
        ctx.stroke();

        // Label for magnetic field
        ctx.textAlign = "left";
        ctx.fillText('magnetic field', 350, 40);
        ctx.fillText('flux density B', 350, 60);

        // --- Draw Figure caption ---
        ctx.textAlign = "center";
        ctx.fillText('Fig. 8.1', canvas.width / 2, 480);

    </script>
</body>
</html>